package com.wk.kxexamadminister.controller;

import com.wk.kxexamadminister.entity.ClassTable;
import com.wk.kxexamadminister.mapper.ClassMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Api(description = "班级操作")
public class ClassController {

    @Autowired
    private ClassMapper classMapper;

    @ApiOperation("增加")
    @PostMapping("/addClass")
    public String addClass(ClassTable classTable){
        int insert = classMapper.insert(classTable);
        if(insert == 1) {
            return "redirect:/findAllClass";
        }
        return "error";
    }

    @ApiOperation("删除")
    @GetMapping("/delClass")
    @ResponseBody
    public String delClass(int cId){
        int i = classMapper.deleteById(cId);
        if(i == 1) {
            return "Success";
        }
        return "No";
    }

    @ApiOperation("修改")
    @GetMapping("/updateClass")
    public String updateClass(ClassTable classTable){
        int i = classMapper.updateById(classTable);
        if(i == 1) {
            return "redirect:/findAllClass";
        }
        return "error";
    }

    @ApiOperation("查找")
    @GetMapping("/findAllClass")
    public String findAll(Model model){
        List<ClassTable> allClass = classMapper.selectList(null);
        model.addAttribute("allClass",allClass);
        return "10-queryAllClassz";
    }




}
